package com.huihua.it.listeners;

import com.huihua.it.utils.SpringUtil;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.bpmn.model.Process;
import org.activiti.bpmn.model.UserTask;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class MyTaskListeners implements TaskListener {

    @Override
    public void notify(DelegateTask delegateTask) {
        System.out.println("delegateTask.getAssignee() = " + delegateTask.getAssignee());
        System.out.println("delegateTask.getVariable: "+delegateTask.getVariable("num"));
        RepositoryService repositoryService = SpringUtil.getObject(RepositoryService.class);
        BpmnModel bpmnModel = repositoryService.getBpmnModel(delegateTask.getProcessDefinitionId());
        Process process = bpmnModel.getProcesses().get(0);
        List<UserTask> userTasks = process.findFlowElementsOfType(UserTask.class);
        for(UserTask userTask: userTasks){
            System.out.println(userTask.getAssignee());
        }
    }
}

